#include <stdio.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include <time.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
static const char *cardNames[] =
{
    "curse",
    "estate",
    "duchy",
    "province",
    "copper",
    "silver",
    "gold",
    "adventurer",
    "council_room",
    "feast",
    "gardens",
    "mine",
    "remodel",
    "smithy",
    "village",
    "baron",
    "great_hall",
    "minion",
    "steward",
    "tribute",
    "ambassador",
    "cutpurse",
    "embargo",
    "outpost",
    "salvager",
    "sea_hag",
    "treasure_map"
};







void showGameState(struct gameState *state)
{
    printf("%20s: %i\n", "numPlayers", state->numPlayers);
    printf("\n------ Supply ------\n");
    for (enum CARD c = curse; c <= treasure_map; c++ )
    {
        printf("%20s: %i\n",  cardNames[c], state->supplyCount[c]);
    }
    printf("\n");

    printf("------ embargoTokens ------\n");
    for (int i = 0; i <= treasure_map; i++)
    {
        printf("%20s: %i\n", cardNames[i], state->embargoTokens[i]);

    }
    printf("\n");

    printf("%20s: %i\n", "outpostPlayed", state->outpostPlayed);
    printf("%20s: %i\n", "outpostTurn", state->outpostTurn);
    printf("%20s: %i\n", "whoseTurn", state->whoseTurn);
    printf("%20s: %i\n", "phase", state->phase);
    printf("%20s: %i\n", "numActions", state->numActions);
    printf("%20s: %i\n", "coins", state->coins);
    printf("%20s: %i\n", "numBuys", state->numBuys);

    // Print players hands
    for (int p = 0; p < MAX_PLAYERS; p++)
    {
        printf("Player %i\'s handCount: %i\n", p, state->handCount[p]);

        printf("Player %i\'s hand: \n", p);
        for (int i = 0; i < state->handCount[p] - 1; i++)
        {
            printf("%s, ", cardNames[state->hand[p][i]]);
        }
        if (state->handCount[p] != 0)
        {
            printf("%s\n", cardNames[state->hand[p][state->handCount[p]]]);
        }
        printf("\n");
    }
    printf("\n");


    // Print players decks
    for (int p = 0; p < MAX_PLAYERS; p++)
    {
        printf("Player %i\'s deckCount: %i\n", p, state->deckCount[p]);

        printf("Player %i\'s deck: \n", p);
        for (int i = 0; i < state->deckCount[p] - 1; i++)
        {
            printf("%s, ", cardNames[state->deck[p][i]]);
        }
        if (state->deckCount[p] != 0)
        {
            printf("%s\n", cardNames[state->deck[p][state->deckCount[p]]]);
        }
        printf("\n");
    }
    printf("\n");

    // Print players discard piles
    for (int p = 0; p < MAX_PLAYERS; p++)
    {
        printf("Player %i\'s discardCount: %i\n", p, state->discardCount[p]);

        printf("Player %i\'s discards: \n", p);
        for (int i = 0; i < state->discardCount[p] - 1; i++)
        {
            printf("%s, ", cardNames[state->discard[p][i]]);
        }
        if (state->discardCount[p] != 0)
        {
            printf("%s\n", cardNames[state->discard[p][state->discardCount[p]]]);
        }
        printf("\n");
    }
    printf("\n");



    printf("%20s: %i\n", "playedCardCount", state->playedCardCount);
    for (int i = 0; i < state->playedCardCount - 1; i++)
    {
        printf("%s, ", cardNames[state->playedCards[i]]);
    }
    if (state->playedCardCount != 0)
    {
        printf("%s\n", cardNames[state->playedCards[state->playedCardCount]]);
    }
    printf("\n");

}







// struct gameState {
//   int numPlayers; //number of players
//   int supplyCount[treasure_map+1];  //this is the amount of a specific type of card given a specific number.
//   int embargoTokens[treasure_map+1];
//   int outpostPlayed;
//   int outpostTurn;
//   int whoseTurn;
//   int phase;
//   int numActions; /* Starts at 1 each turn */
//   int coins; /* Use as you see fit! */
//   int numBuys; /* Starts at 1 each turn */
//   int hand[MAX_PLAYERS][MAX_HAND];
//   int handCount[MAX_PLAYERS];
//   int deck[MAX_PLAYERS][MAX_DECK];
//   int deckCount[MAX_PLAYERS];
//   int discard[MAX_PLAYERS][MAX_DECK];
//   int discardCount[MAX_PLAYERS];
//   int playedCards[MAX_DECK];
//   int playedCardCount;
// };
